/*
	@file: log/include/LogRunner.h
	@author: Wolfhead
 */
#ifndef _LOG_LOG_RUNNER_H_
#define _LOG_LOG_RUNNER_H_


#include "LogPriority.h"
#include "detail/SyncQueue.h"
#include "logger/Logger.h"
#include "formatter/Formatter.h"
#include "LogOption.h"
#include "LogData.h"

namespace logger
{

class LogRunner;
typedef boost::shared_ptr<LogRunner> LogRunnerPtr;

class LogRunner
	: public boost::enable_shared_from_this<LogRunner>
	, public boost::noncopyable
{
public:

	LogRunner(const LogOption& option);

	~LogRunner();

	// start the logging thread
	// if a thread is already running, stop the running thread
	// and start a new one
	int start();

	// stop the runner thread
	// wait until the thread exit
	int stop();

	int run();

	int run_once();

	int restart();

	int log(LogDataPtr data_ptr);

	const std::string get_name()
	{
		return m_name;
	}

	void set_name(const std::string& name)
	{
		m_name = name;
	}

	const LogOption& get_option();

	void set_option(const LogOption& option);

private:

	typedef SyncQueue<LogDataPtr> Queue;
	typedef Queue::QueueType SpliteQueue;

	std::string				m_name;
	LogOption				m_option;

	Queue	                m_queue;
	SpliteQueue 			m_split_queue;

	boost::shared_ptr<boost::thread> m_thread_ptr;
	bool 					m_running;
};

} //namespace logger

#endif
